﻿using System.Resources;
using YWM.Common;
using YWM.Session;

namespace YWM.Localization
{
    /// <summary>
    /// 语言管理类
    /// </summary>
    public class LocalizationManager : ILocalizationManager
    {
        private readonly ResourceManager _resourceManager;
        private readonly ISession _session;
        public LocalizationManager(ResourceManager resourceManager, ISession session)
        {
            _resourceManager = resourceManager;
            _session = session;
        }

        public string Culture
        {
            get
            {
                return _session.Culture;
            }
            set
            {
                _session.Culture = value;
            }
        }

        public string this[string name]
        {
            get
            {
                return GetString(name);
            }
        }

        /// <summary>
        /// 根据name获取对应的语言
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetString(string name)
        {
            string value = LangUtil.GetString(name, _resourceManager, Culture);
            return value;
        }
    }
}
